package com.Akronmcp.hb;

import java.io.File;

import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import com.Akronmcp.hta.main.HComer;
import com.Akronmcp.hta.obj.HManager;


public class HbM extends JavaPlugin{
	
	public static FileConfiguration conf;
	public static FileConfiguration lang;
	
	public static File df;
	
	public final static HManager hta = new HManager();

	public static JavaPlugin ins;
	
	@Override
	public void onEnable()
	{
		ins = this;
		
		df = getDataFolder();
   	 
	   	 if(!df.exists())
	   	 {
	   	   File filelangf=new File(df,"lang");
	   	   getDataFolder().mkdir(); 
	   	   filelangf.mkdir();
	   	   
		   	try
		   	 {
		   	  saveResource("config.yml", false);
		   	  saveResource("books.yml", false);   	  
		   	  saveResource("lang/ZH_CN.yml", false);
		   	  //读取配置文件
		   	 }catch(Exception e)
		   	 {
		   		 e.printStackTrace();
		   	 }
		   	   
	   	 }
	   	 //创建插件数据目录and lang
		
   	 
	    getServer().getPluginManager().registerEvents(new HbListener(), (Plugin)this);
  	    //注册监听器
	   	
	    CommandExecutor comer = new HbComer();
        getCommand("hb").setExecutor(comer);

        getCommand("hb").setTabCompleter((TabCompleter) comer);
     
  	    //注册指令执行器
	    
        try {
        	HbLoader.reload_conf();
        	//载入配置
        	System.out.println(HComer.help("loadok"));

        }catch (Exception e) {
        	e.printStackTrace();
        	System.out.println(HComer.help("loadok"));
		}
	   	
		getLogger().info("HopBookMenu已启动");
		
	}
	
	
	public void onDisable()
	{
		hta.clearAll();
	}
  

}
